package net.zjitc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.zjitc.entity.Company;
import net.zjitc.entity.Mycompany;
import net.zjitc.mapper.CompanyMapper;
import net.zjitc.mapper.MycompanyMapper;
import net.zjitc.service.IMycompanyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @auther 郭梦婷
 * @create 2022-05-30 21:34:03
 * @describe 服务实现类
 */
@Service
@Transactional
public class MycompanyServiceImpl extends ServiceImpl<MycompanyMapper, Mycompany> implements IMycompanyService {

    @Autowired
    private MycompanyMapper mycompanyMapper;
    @Autowired
    private CompanyMapper companyMapper;

    @Override
    public Mycompany IfAttention(String companyid, String username) {
        QueryWrapper<Mycompany> wrapper=new QueryWrapper<>();
        wrapper.eq("companyid",companyid).eq("username",username);
        Mycompany mycompany = mycompanyMapper.selectOne(wrapper);
        return mycompany;
    }

    @Override
    public int DeleteAttention(String companyid, String username) {
        QueryWrapper<Mycompany> wrapper=new QueryWrapper<>();
        wrapper.eq("companyid",companyid).eq("username",username);
        int delete = mycompanyMapper.delete(wrapper);

        return delete;
    }

    @Override
    public Page<Company> getAllAttentionByUsername(String username, Integer pagenum, Integer pagesize) {
        Page<Company> page=new Page<>(pagenum,pagesize);
        page=companyMapper.getAllAttentionByUsername(page,username);
        return page;
    }
}
